package com.lgt_enterprise_android.utils;

import android.content.Context;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lgt_enterprise_android.Constant;

import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class HttpManager {
    //获取oss的STS
    public static void getSTS(Context context, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/basic/sts";
        BasicHttp.getExec(context, url, callBack);
    }

    //发送验证码 登录
    public static void sendmsgCode(Context context, String phoneNum, String _type, BasicHttp.IMyCallBack callBack) {
        JSONObject jo = new JSONObject();
        jo.put("phoneNumber", phoneNum);
        jo.put("type", _type);

        RequestBody requestBody = RequestBody.create(jo.toJSONString().getBytes(), MediaType.parse("application/json;charset=UTF-8"));
        String url = Constant.URL + "api/basic/sms_by_login";
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //发送验证码
    public static void sendmsgCodeByChangePhone(Context context, String phoneNum, BasicHttp.IMyCallBack callBack) {
        JSONObject jo = new JSONObject();
        jo.put("phoneNumber", phoneNum);
        jo.put("type", "UPDATE_ENTERPRISE");

        RequestBody requestBody = RequestBody.create(jo.toJSONString().getBytes(), MediaType.parse("application/json;charset=UTF-8"));
        String url = Constant.URL + "api/basic/sms_by_update";
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //验证码登录
    public static void smsLogin(Context context, String phoneNum, String smsCode, BasicHttp.IMyCallBack callBack) {

        RequestBody requestBody = new FormBody.Builder()
                .add("phone_num", phoneNum)
                .add("sms_code", smsCode)
                .add("app_type", "2")
                .add("account_type", "2")
                .build();

        String url = Constant.URL + "api/login";
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //账号和密码登录
    public static void login(Context context, String phoneNum, String pwd, BasicHttp.IMyCallBack callBack) {
        RequestBody requestBody = new FormBody.Builder()
                .add("username", phoneNum)
                .add("pwd", pwd)
                .add("app_type", "2")
                .add("account_type", "1")
                .build();

        String url = Constant.URL + "api/login";
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //获取部门接口
    public static void getBranch(Context context, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/my_org";
        RequestBody requestBody = new FormBody.Builder().build();
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //加入组织接口
    public static void selectWhichBranch(Context context, String currentOrgId, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/org_space?currentOrgId=" + currentOrgId;
        BasicHttp.getExec(context, url, callBack);
    }

    //获取组织信息
    public static void getCompanyInfo(Context context, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/organization/find";
        BasicHttp.getExec(context, url, callBack);
    }


    //获取灵工列表
    public static void getStaffList(Context context, int pageNum, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/worker/find_page?type=FLEXIBLE&pageSize=15&pageNumber=" + pageNum;
        BasicHttp.getExec(context, url, callBack);
    }

    //获取灵工详情
    public static void getStaffDetail(Context context, String staff_id, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/worker/find?id=" + staff_id;
        BasicHttp.getExec(context, url, callBack);
    }

    //获取员工列表
    public static void getWorkerList(Context context, int pageIndex, int pageSize, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/worker/find_page?type=FIXATION&pageSize=" + pageSize + "&pageNumber=" + pageIndex;
        BasicHttp.getExec(context, url, callBack);
    }

    //员工离职
    public static void workerLeft(Context context, String worker_id, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/worker/termination?id=" + worker_id;
        BasicHttp.getExec(context, url, callBack);
    }

    //员工离职
    public static void inviteStaff(Context context, JSONArray jsonArray, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/worker/invite";

        RequestBody requestBody = RequestBody.create(jsonArray.toJSONString().getBytes(), MediaType.parse("application/json;charset=UTF-8"));
//        RequestBody requestBody = new FormBody.Builder()
//                .add("request", data)
//                .build();
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //获取个人信息
    public static void getProfileInfo(Context context, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/my_info";
        BasicHttp.getExec(context, url, callBack);
    }

    //保存个人信息
    public static void saveProfileInfo(Context context, String bodyInfo, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/update_my_info";
        RequestBody requestBody = RequestBody.create(bodyInfo.getBytes(), MediaType.parse("application/json;charset=UTF-8"));
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //保存企业信息
    public static void saveEnterPriseInfo(Context context, String bodyInfo, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/organization/update";
        RequestBody requestBody = RequestBody.create(bodyInfo.getBytes(), MediaType.parse("application/json;charset=UTF-8"));
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //添加企业邀请码
    public static void setInviteCode(Context context, String inviteCode, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "api/e/organization/set_invite_code?inviteCode=" + inviteCode;
        BasicHttp.getExec(context, url, callBack);
    }

    //修改密码
    public static void editPwd(Context context, String oldPwd, String newPwd, BasicHttp.IMyCallBack callBack) {
        JSONObject jo = new JSONObject();
        jo.put("newPwd", newPwd);
        jo.put("oldPwd", oldPwd);
        RequestBody requestBody = RequestBody.create(jo.toJSONString().getBytes(), MediaType.parse("application/json;charset=UTF-8"));
        String url = Constant.URL + "api/e/account/set_account_pwd";
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //获取抢班列表
    public static void getArragetList(Context context, String time, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "/api/e/arrange/findList?date=" + time;
        BasicHttp.getExec(context, url, callBack);
    }

    //添加排班
    public static void addArrange(Context context, String time, String data, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "/api/e/arrange/operation";
        RequestBody requestBody = RequestBody.create(data.getBytes(), MediaType.parse("application/json;charset=UTF-8"));
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //修改手机号
    public static void editPhone(Context context, String newPhoneNumber, String verificationCode, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "/api/e/account/reset_phone_number";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("newPhoneNumber", newPhoneNumber);
        jsonObject.put("verificationCode", verificationCode);

        RequestBody requestBody = RequestBody.create(jsonObject.toJSONString().getBytes(), MediaType.parse("application/json;charset=UTF-8"));
        BasicHttp.postExec(context, url, requestBody, callBack);
    }

    //get skill tags by position
    public static void getSkillsByPosition(Context context, String pos, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "/api/e/position/skill_tag_by_position_id?positionId=" + pos;
        BasicHttp.getExec(context, url, callBack);
    }

    //get qiangban list
    public static void getQiangBanList(Context context, int pageNum, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "/api/e/arrange/published?pageSize=15&pageNum=" + pageNum;
        BasicHttp.getExec(context, url, callBack);
    }

    //get staff list that not join
    public static void getStaffListUnJoin(Context context, int pageNum, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "/api/e/invite_record/find_list";
        JSONObject jo = new JSONObject();
        jo.put("pageSize", 15);
        jo.put("pageNum", pageNum);
        RequestBody requestBody = RequestBody.create(jo.toJSONString().getBytes(), MediaType.parse("application/json;charset=UTF-8"));
        BasicHttp.postExec(context, url, requestBody, callBack);
    }


    //    http://lgt-test.ds78.com.cn/static/lgt-e-version.json
    //check update
    public static void checkUpdate(Context context, BasicHttp.IMyCallBack callBack) {
        String url = Constant.URL + "static/lgt-e-version.json";
//        JSONObject jo=new JSONObject();
//        jo.put("current", AppUtil.getVersionName(context));
//        jo.put("type", AppUtil.getVersionName(context));
//        jo.put("pageNum",pageNum);
//        RequestBody requestBody =RequestBody.create(jo.toJSONString().getBytes(), MediaType.parse("application/json;charset=UTF-8"));
        BasicHttp.getExec(context, url, callBack);
    }


}
